package cn.wolfcode.util;

import cn.wolfcode.domain.Employee;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;
import java.util.List;

public class UserContext {
    public static final String USER_IN_SESSION = "USER_IN_SESSION";
    public static final String EXPRESSIONS_IN_SESSION = "EXPRESSIONS_IN_SESSION";
    public static void setCurrentUser(Employee employee){
        UserContext.getSession().setAttribute(USER_IN_SESSION,employee);
    }
    public static void setExpressions(List<String> expressions){
        UserContext.getSession().setAttribute(EXPRESSIONS_IN_SESSION,expressions);
    }
    public static List<String> getExpressions(){
        return (List<String>)UserContext.getSession().getAttribute(EXPRESSIONS_IN_SESSION);
    }
    public static Employee getCurrentUser(){
        return (Employee)UserContext.getSession().getAttribute(USER_IN_SESSION);
    }
    public static HttpSession getSession() {
        ServletRequestAttributes attrs =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        return attrs.getRequest().getSession();
    }
}
